package com.p595263720.o_amap.search.model;

import com.amap.api.maps.model.LatLng;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.poisearch.PoiSearch;

import java.util.ArrayList;
import java.util.List;

public class UnifiedSearchBound {

    private LatLng lowerLeft;
    private LatLng upperRight;
    private LatLng center;
    private int range;
    private String shape;
    private boolean isDistanceSort;
    private List<LatLng> polyGonList = new ArrayList<>();

    public UnifiedSearchBound(PoiSearch.SearchBound bound){
        if(bound!=null){
            this.lowerLeft = toLatLng(bound.getLowerLeft());
            this.upperRight = toLatLng(bound.getUpperRight());
            this.center = toLatLng(bound.getCenter());
            this.range = bound.getRange();
            this.shape = bound.getShape();
            this.isDistanceSort = bound.isDistanceSort();
            List<LatLonPoint> lonPoints = bound.getPolyGonList();
            if(lonPoints!= null){
                for (LatLonPoint lonPoint : lonPoints) {
                    polyGonList.add(toLatLng(lonPoint));
                }
            }
        }

    }

    /**
     * 中心点 + 半径番位
     */
    public PoiSearch.SearchBound toSearchBoundCenterRange(){
        if(this.center!=null && this.range !=0){
            return new PoiSearch.SearchBound(toLatLonPoint(this.center),this.range);
        }
        return null;
    }


    public static LatLng toLatLng(LatLonPoint latLonPoint){
        if(latLonPoint!=null){
            double latitude = latLonPoint.getLatitude();
            double longitude = latLonPoint.getLongitude();
            return new LatLng(latitude,longitude);
        }else {
            return null;
        }

    }

    public static LatLonPoint toLatLonPoint(LatLng latLng){
        if(latLng != null){
            double latitude = latLng.latitude;
            double longitude = latLng.longitude;
            return new LatLonPoint(latitude,longitude);
        }else {
            return null;
        }

    }
}
